<%@page import="com.alibaba.fastjson.JSON"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="beans.*"%>
<%@ page import="com.alibaba.fastjson.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
* {
	margin: 0px;
	padding: 0px;
}

p {
	text-indent: 2em;
	line-height: 1.3em;
	font-size: 13px;
}

table{
	margin:10px;
	border-collapse: collapse;
	font-size:15px;
	width:95%;
	
}

tr{
	border-bottom:1px solid gray;	
}

th{
	text-align: left;
}


</style>
</head>
<body>
	<%
		//1模拟得到数据
		String[] usernos = { "1101", "1102", "1103" };
		String[] userpwds = { "123", "124", "125" };
		String[] usernames = { "张三", "李四", "王五" };
		String[] usersexs = { "男", "男", "女" };
		String[] userinterests = { "足球-篮球", "足球-电影", "电影-小说" };

		List<Map<String, Object>> list = new ArrayList<>();

		for (int i = 0; i < usernos.length; i++) {
			Map<String, Object> map2 = new HashMap<>();
			map2.put("userno", usernos[i]);
			map2.put("userpwd", userpwds[i]);
			map2.put("username", usernames[i]);
			map2.put("usersex", usersexs[i]);
			map2.put("userinterest", userinterests[i]);
			list.add(map2);
		}
		
		
		//下面为jstl方式显示做准备
		String test="bb";
		pageContext.setAttribute("test", test);
		pageContext.setAttribute("list", list);
		
		//如果list等转成json对象，使用jstl也是可以的，所以，使用ajax，使用服务端的json也是可以的，原来都是使用客户端的json
		
		String jsonstr=JSON.toJSONString(list);
		JSONArray jsonarray=JSONArray.parseArray(jsonstr);
		pageContext.setAttribute("list2", jsonarray);
		
		//从下面是正式从数据库中取出的数据，放在div4中
		List<Map<String, Object>> list4= null;
		UserDAO userDAO=new UserDAO();
		list4=userDAO.findall();
		pageContext.setAttribute("list4", list4);
		
	
	%>
	
	
	<div id="all">
		<table>
			<tr>
				<th>号码</th>
				<th>密码</th>
				<th>姓名</th>
				<th>性别</th>
				<th>兴趣</th>
			</tr>
			<%
				for(int i=0;i<list.size();i++){
					%>
					<tr>
						<td><%=list.get(i).get("userno") %></td>
						<td><%=list.get(i).get("userpwd") %></td>
						<td><%=list.get(i).get("username") %></td>
						<td><%=list.get(i).get("usersex") %></td>
						<td><%=list.get(i).get("userinterest") %></td>
					</tr>
				<%}
			%>
		</table>	
	</div>
	
	下面使用服务端的list，用jstl表达<br>
	<div id="all2">
		<table>
			<tr>
				<th>号码</th>
				<th>密码</th>
				<th>姓名</th>
				<th>性别</th>
				<th>兴趣</th>
			</tr>
			<c:forEach var="temp" items="${list }">
				<tr>
					<td>${temp.userno}</td>
					<td>${temp['userpwd']}</td>
					<td>${temp.username}</td>
					<td>${temp.usersex}</td>
					<td>${temp.userinterest}</td>
				</tr>
			</c:forEach>			
		</table>	
	</div>
	
	下面使用服务端的json，用jstl表达,不过没有必要了吧，因为上面列表已经可以满足jstl表达的需求<br>
	<div id="all3">
		<table>
			<tr>
				<th>号码</th>
				<th>密码</th>
				<th>姓名</th>
				<th>性别</th>
				<th>兴趣</th>
			</tr>
			<c:forEach var="temp" items="${list2 }">
				<tr>
					<td>${temp.userno}</td>
					<td>${temp['userpwd']}</td>
					<td>${temp.username}</td>
					<td>${temp.usersex}</td>
					<td>${temp.userinterest}</td>
				</tr>
			</c:forEach>			
		</table>	
	</div>
	
	下面使用真正的数据库中数据，放入到list4，用jstl表达<br>
	<div id="all4">
		<table>
			<tr>
				<th>号码</th>
				<th>密码</th>
				<th>姓名</th>
				<th>性别</th>
				<th>兴趣</th>
			</tr>
			<c:forEach var="temp" items="${list4 }">
				<tr>
					<td>${temp.userno}</td>
					<td>${temp['userpwd']}</td>
					<td>${temp.username}</td>
					<td>${temp.usersex}</td>
					<td>${temp.userinterest}</td>
				</tr>
			</c:forEach>			
		</table>	
	</div>
</body>
</html>